// Created by WXX on 2021/11/17 9:49
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/**
 * 执行用时：24 ms, 在所有 C++ 提交中击败了6.08%的用户
 * 内存消耗：10.5 MB, 在所有 C++ 提交中击败了6.58%的用户
 */
class Solution {
public:
    vector<int> selfDividingNumbers(int left, int right) {

        vector<int> res;
        for (int i = left; i <= right; i++)
            if (check(i))
                res.push_back(i);
        return res;
    }

    bool check(int n) {

        int x = n;
        vector<int> nums;
        while (x) {
            int t = x % 10;
            if (!t) return false;
            nums.push_back(t);
            x /= 10;
        }
        for (auto t : nums)
            if (n % t != 0)
                return false;
        return true;
    }
};

void OutputBasicArray1D(vector<int> nums) {
    cout << "[";
    for (int i = 0; i < nums.size(); i++) {
        cout << nums[i];
        if (i != nums.size() - 1) cout << ", ";
    }
    cout << "]" << endl;
}

int main() {

    OutputBasicArray1D(Solution().selfDividingNumbers(1, 22));

    return 0;
}
